package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.custom.converter.StringToItemTypeConverter;
import com.atguigu.lease.web.admin.custom.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Admin
 * @title: WebMvcConfiguration
 * @projectName lease
 * @description: WebMvcConfiguration
 * @date 2025/1/29 16:27
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    //@Autowired
    //private StringToItemTypeConverter stringToItemTypeConverter;
    ////注册stringToItemTypeConverter转换器

    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;
    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        //registry.addConverter(this.stringToItemTypeConverter);
        //注册通用转换器
        registry.addConverterFactory(this.stringToBaseEnumConverterFactory);
    }

    /**
     * 添加请求拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.authenticationInterceptor).
                addPathPatterns("/admin/**").excludePathPatterns("/admin/login/**");
    }

}
